import { createStore } from 'vuex'
import createPersistedState from 'vuex-persistedstate';
export default createStore({

  state() {
    return {
      user: null,
    };
  },
  mutations: {
    setUser(state, user) {
      state.user = user;
    },
  },
  actions: {
    loginUser({ commit }, user) {
      commit('setUser', user);
    },
    logout({ commit }) {
      // 清除 Vuex 状态
      commit('resetUser');
      // 清除 localStorage 中的持久化状态
      window.localStorage.removeItem('rabbitstore-client');
      // 其他登出逻辑...
    },
  },
  plugins: [
    // veux持久化配置
    createPersistedState({
      key: 'rabbitstore-client',
      paths: ['user']
    })
  ]
})
